Error in pgsql2shp postgresql - database

I want to dump a shapefile from my postgresql database with the following command line:
pgsql2shp -f output.shp -h localhost -u postgres -P admin parcel "SELECT * FROM parcel.export_output WHERE ParcelNoEng=116"
but it goes on showing the error:
ERROR: function postgis_version() does not exist
LINE 1: SELECT postgis_version()
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
What shall I do to get it work?
I have added Postgresql/version/bin to my environmental variable.

You're missing the PostGIS extension. Execute the following command in your PostgreSQL using a client of your choice, e.g. psql, and try again:
CREATE EXTENSION postgis;

Related

MSSQL sp_dropextendedproperty are not permitted

I am new to MSSQL, and I am trying to move db from one server to another.
I am using SQLCMD to restore the DB
However, I am stuck on the following line, (script has many like these I just took one for sake of example)
on running SQLCMD -S servername\SQLEXPRESS -U myuser -P somepassword#1234 -i C:\1.sql -o C:\1.txt which has following code
USE [MoodleNew]
GO
EXEC sys.sp_dropextendedproperty
#name=N'MS_SSMA_SOURCE' ,
#level0type=N'SCHEMA',
#level0name=N'my_schema',
#level1type=N'TABLE',
#level1name=N'my_table_name'
GO
I am getting following error
Object is invalid. Extended properties are not permitted on 'my_schema.my_table_name', or the object does not exist.
No idea what the issue is, any help will be appreciated.

Managing error messages generated by Postgres \copy command

I am working on a tool to import large sets of files into a Postgres database. Currently I have a working prototype - a bash script going over the list of files, and using psql with the \copy command to import each file.
I would like to add some error handling; I'm thinking of parsing error messages to generate feedback for users, but I can't find a specification, or a list of error messages that are generated by the \copy command in particular.
Is there a tool, or a library, or even a reference list that I could use? I am constrained to use either Shell or Node with the Postgres module.
That should be fairly simple; just check the return code:
psql -c "\copy ${atable} FROM '${afile}' (FORMAT 'csv')"
if [ $? -ne 0 ]; then
echo "copy failed!"
fi

T-SQL error if use dollar and bracket symbols together

I'm getting the following error message with execution T-SQL script with this construction "$(", in sqlcmd utility:
C:\Users\Admin>sqlcmd -S DESKTOP-5AA9JIA\SQLEXPRESS -q "select '$(' " -R
Sqlcmd: Error: Syntax error at line 1 near command '''.
1>
if run this script via SSMS then everything works smoothly.
Getting the same error, when using INSERT INTO statement or any other statement.
Any suggestion on how to resolve it?
You should use -x when launch sqlcmd to ignore scripting variables.
-x
Causes sqlcmd to ignore scripting variables. This is useful when a
script contains many INSERT statements that may contain strings that
have the same format as regular variables, such as $(variable_name).
sqlcmd Utility
When sqlcmd parser sees $(it expects scripting variable that is not provided so it throws the error.
Here is my test:

Postgres pg_dump issue

Good Day,
I've been trying to restore a dump file using the psql client and I'm getting this error:
psql.bin:/home/user/Desktop/dump/dumpfile.sql:907:
ERROR: more than one function named "pg_catalog.avg"
CONTEXT: COPY pg_aggregate, line 1, column aggfnoid: "pg_catalog.avg"
I created the dump file from a different Postgres DB (version: 9.4.5) using the command:
pg_dump --username=pgroot ${tables} --no-owner --no-acl --no-security
--no-tablespaces --no-unlogged-table-data --data-only dbname > dumpfile.sql
Where ${tables} is a variable in the for:
-T table1 -T table2 -T table3 ...
This is because I'm dumping specific tables listed in a new-line delimited file. Hence its not the entire database but specific tables I want to dump.
I tried loading the the dump file int another Postgres DB (9.6) using the following command:
psql -d dbname -U superuser -v "ON_ERROR_STOP=1" -f
${DUMP_DIR}dumpfile.sql -1 -a > ${LOG_ERR_DIR}dumpfile.log
2>${LOG_ERR_DIR}dumpfile.err
This gave the error mentioned above. It seems this error is occurring because the dump file tries to add the function "pg_catalog.avg" to the database and it gives an error because it already exists.
The sql file generated by the pg_dump does not have anywhere in it where it creates the pg_catalog.avg function, so i don't know why this is occurring.
So I tried dropping the database and creating it from template0, and still I got the error. It seems to me that its a bug based on the follwoing post:
Re: BUG #6176: pg_dump dumps pg_catalog tables
I'm stuck trying to reslove this issue. If anyone can help me resolve this issue please respond?
Thank you in advance,
j3rg
I found out what was causing this issue. It seems that there was an extra newline in the file containing the table listing. This was causing an extra table argument with no table specified and in turn pg_dump exported the sys tables into the file. I file I was searching for the avg function was the wrong file too.

Need sqsh to ignore a dollar sign

The Environment:
Solaris 10, /bin/sh script using sqsh and freetds to talk to an MS SQL Server
The (TLDR) Problem:
I need sqsh to ignore a dollar sign and pass it through to MS SQL.
The Background:
I'm writing some code that dynamically builds SQL to alter existing indexes but when it runs, I get errors:
Msg 2727, Level 11, State 1
Server 'HOST\SERVER', Line 1
Cannot find index 'foo'.
I dig around and see that there is no index named foo but there is one named foo$bar.
The built-up input SQL input looks fine...
% grep 'foo' input.sql
alter index [foo$bar] on ...
...and running this SQL through a New Query session or a third party app succeeds. However, the results when passed through sqsh don't see past that dollar sign:
% sqsh -e -i input.sql -o output.sql
% grep 'foo' output.sql
1> alter index [foo] on ...
...which suggests it's interpreting $bar as a variable or something.
Anyone know how to get sqsh to escape a dollar sign or allow one to pass through? I've tried various combinations of quotes and backslashes.
Help me, stackoverlow. You're my only hope.
Another option is to disable buffer expansion altogether by executing:
\set expand=0
on the sqsh prompt, or specify this command in the .sqshrc file, or start sqsh with the parameter
sqsh -e -i input.sql -o output.sql -Lexpand=0
If expansion is on (default) then sqsh will substitute the variable $bar with its contents.
Reference manual on page 5 states: "Note that in order to prevent the expansion of a variable use either single quotes, or two \’s, like thus:
1> \echo \\$name
$name
So, I believe that to prevent sqsh to substitute $bar with an empty string, you have to write something like:
alter index [foo\\$bar] on ...
alter index ['foo$bar'] on ...
To test it you can try first with SELECT 'foo\\$bar' = 1 or something similar.

Resources