How to properly use plain SQL code in Postgresql? - postgresql

I'm using pgadmin right now and this is the table I created. I'm trying to convert this wkb_geometry column into lat,lon geometry point.
When I tried to select this column and declare it as a variable so I can perform some conversion on it, I failed to do so by using plain SQL code such as "DECLARE #xxx VarChar". I looked it up and did see that plain SQL code doesn't always work in Postgres but haven't found a solution yet. Could someone point me a way to do it? Thank you so much!!

Related

SAS SQL Pass-Through Facility does not work as expected for Postgres database

I am working with SCD Type 2 transformation in SAS Data integration Studio (4.905) and using Postgres (12) as database.
I am facing the following error when I try to execute a query via passthrough:
When using passthrough in Postgres, SCD Type 2 doesn't enclose the table name in quotes (which would keep the name uppercase, since postgres converts all unquoted data to lowercase) and so doesn't find it as you can see.
My questions are:
Is there a way to make SCD2 transformation declare the table’s name, used via passthrough, in quotes?
Is there a way to make the SCD2 transformation create intermediate tables ‘name in lower case so that the reference is not lost when doing passthrough?
Is there a global option in DI that allow us to modify/edit temporary table names?
Source and target tables are postgresql tables, with name and columns name in lowercase:
Please, if anyone has faced this problem before or knows what is missing, please, let I know.
To solve this issue, we have to select the following highlighted (source and target) table options. It results in quotes around source/target table names:
Then, SCD2 transformation automatically put quotes in tables y columns names as you can see:

Check if an extension is in use before dropping it in a postgres db

I want to drop unnecessary extensions in my database. But before i do that , i want to make sure that they are not being used anywhere in the database. I have tried using the below query to find functions that make use of the extension like pgcrypto . Im not sure if this is enough
select proname,prosrc from pg_proc where prosrc ilike '% encrypt%'
There is no good way to do that.
Your example shows that it is difficult to check if extensions are used in database functions, but you will never be able to tell if SQL statements sent from the client use the extension just by querying the database.

How to view bytea column data in a SELECT statement?

I need to know how to visualize binary content in a postgresql table, whose column is of type bytea.
I found a possible solution to that problem, and it works well.
SELECT text(column_name) FROM table_name;
Do you know any other manner to accomplish this goal?
All rigth my friend, go ahead that is the solution.
The function text is used to decode bytea into string.

Not able to query after Alter table in DB2

We have a table someone created in DB2. I have no idea how they created it. But when I edit the table, It edits just fine. But after edit I can not query the table at all THE COLUMN CANNOT BE ADDED TO THE TABLE BECAUSE THE TABLE HAS AN EDIT PROCEDURE.
I looked ibm site and found this how to edit table using procedure
But I have no idea how to do this.
Is there anything that I can do to fix this with out following the procedure mentioned in second link?
I restarted server, but still no help. First I'm not able to figure out why I get the error in first place.
I'm using DB Visualizer and DB2 on linux.
This is sometimes default behavior of DB2. We need to run reorgchk command to fix these errors. More info below..
http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.admin.doc/doc/r0000888.htm
http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.admin.doc/doc/c0023297.htm

Why does my typed dataset not like temporary tables?

I am attempting add a tableadapter to a stored procedure in my SQL Server 2005 Express. The stored procedure, however, uses a temporary table called #temp. When creating the table adapter, Visual Studio complains "Unknown Object '#temp'" and says that the stored procedure returns 0 columns. This is problematic because I use that stored procedure with a crystal report, and need those columns.
How can I fix this?
Bizarre. According to this you add
IF 1=0 BEGIN
SET FMTONLY OFF
END
to the SP right after the AS part of the SP and it works. Visual Studio now has no problem with it. I have no idea why this works like this, or why it would work, but it does.
This may be an old thread and the answer is found, but when someone gets into your stored procedure after and see this code, he really does not understand. There is another way to do this properly and it is to simply declare the table as a variable like this :
DECLARE #temp TABLE
(
SomeText1 nvarchar(255),
SomeText2 nvarchar(255)
)
Also, don't forget to remove the DROP TABLE at the end.
PS : If you really need to use the temporary table because you need to create it, then you have to write the code given in the previous answer. Hope this helps.